home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d2 / testemm.arc / TESTEMM.CPP < prev    next >
C/C++ Source or Header  |  1989-12-24  |  3KB  |  118 lines

  1. #include <stdio.h>
  2. #include <handle.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <stream.hpp>
  6. #include <time.h>
  7. #include <dos.h>
  8.  
  9. #define N_PTRS 16
  10. #define MAX_EMM_BLOCK_SIZE 16372
  11. #define ITERATION_LIMIT 16384
  12.  
  13. typedef struct mystruct
  14.    {
  15.    int   n;
  16.    char  buf[1];
  17.    } MYSTRUCT;
  18.  
  19. typedef MYSTRUCT far *        MAINPTR;
  20. typedef MYSTRUCT __handle *   EMMPTR;
  21.  
  22. MAINPTR  mainptr[N_PTRS];
  23. EMMPTR   emmptr[N_PTRS];
  24. MYSTRUCT *disk_buffer;
  25.  
  26. main()
  27.    {
  28.    int i,j,k,outer_loop_cnt;
  29.    clock_t start,end;
  30.    double main_time_in_secs, emm_time_in_secs, ratio;
  31.    int div_factor = 8;
  32.    int blocksize;
  33.  
  34.    printf("\tBlocksize\tMain mem time\tEMM time\tRatio\n");
  35.  
  36.    for(div_factor = 8 ; div_factor > 0 ; --div_factor)
  37.       {
  38.       blocksize = MAX_EMM_BLOCK_SIZE / div_factor;
  39.  
  40.       for(i = 0 ; i < N_PTRS ; ++i)
  41.          {
  42.          mainptr[i] = farmalloc(blocksize);
  43.          if(mainptr[i] == NULL)
  44.             {
  45.             printf("Unable to allocate mainptr[%d]\n",i);
  46.             for(j = 0 ; j < i ; ++j)
  47.                {
  48.                farfree(mainptr[j]);
  49.                handle_free(emmptr[j]);
  50.                exit(0);
  51.                }
  52.             }
  53.  
  54.          mainptr[i]->n = i;
  55.  
  56.          emmptr[i] = handle_malloc(blocksize);
  57.          if(emmptr[i] == NULL)
  58.             {
  59.             printf("Unable to allocate emmptr[%d]\n",i);
  60.             farfree(mainptr[i]);
  61.             for(j = 0 ; j < i ; ++j)
  62.                {
  63.                farfree(mainptr[j]);
  64.                handle_free(emmptr[j]);
  65.                exit(0);
  66.                }
  67.             }
  68.  
  69.          if(!handle_ishandle(emmptr[i]))
  70.             printf("emmptr[%d] is NOT a handle\n",i);
  71.  
  72.          emmptr[i]->n = i;
  73.          }
  74.  
  75.       for(outer_loop_cnt = 1 ; outer_loop_cnt <= 5 ; ++outer_loop_cnt)
  76.          {
  77.          start = clock();
  78.  
  79.          for(i = 0 ; i < ITERATION_LIMIT ; ++i)
  80.             {
  81.             for(j = 0 ; j < N_PTRS ; ++j)
  82.                k = mainptr[j]->n;
  83.             }
  84.  
  85.          end = clock();
  86.  
  87.          main_time_in_secs = ((double)(end - start)) / ((double)CLK_TCK);
  88.  
  89.          start = clock();
  90.  
  91.          for(i = 0 ; i < ITERATION_LIMIT ; ++i)
  92.             {
  93.             for(j = 0 ; j < N_PTRS ; ++j)
  94.                k = emmptr[j]->n;
  95.             }
  96.  
  97.          end = clock();
  98.  
  99.          emm_time_in_secs = ((double)(end - start)) / ((double)CLK_TCK);
  100.  
  101.          ratio = emm_time_in_secs / main_time_in_secs;
  102.  
  103.          if(outer_loop_cnt == 1)
  104.             printf("\t%d\t\t%6.3f\t\t%6.3f\t\t%6.3f\n", blocksize,
  105.                    main_time_in_secs, emm_time_in_secs, ratio);
  106.          else
  107.             printf("\t\t\t%6.3f\t\t%6.3f\t\t%6.3f\n", main_time_in_secs,
  108.                    emm_time_in_secs, ratio);
  109.          }
  110.  
  111.       for(i = 0 ; i < N_PTRS ; ++i)
  112.          {
  113.          farfree(mainptr[i]);
  114.          handle_free(emmptr[i]);
  115.          }
  116.       }
  117.    }
  118.